<meta charset="utf-8">
<form method="post" action="" style="text-align: center;padding-top: 50px;">
	用户名:<input type="text" name="username"><br/><br/>
	密码:<input type="password" name="password"><br/><br/>
	<input type="submit" name="submit" value="登录" style="width: 200px;height: 30px;">
</form>
<?php
if(isset($_POST["submit"])&&$_POST["submit"]=="登录"){
	//是登录按钮触发的事件
	$username=$_POST["username"];
	$password=$_POST["password"];
	//查询数据库 看看是否存在匹配的用户
	$selectusersql="select * from userinfos where username='$username' and password='$password'";
	include_once("database.php");
	$result=@mysql_query($selectusersql) or die("登录失败:".mysql_error()."<br/>");
	if(mysql_num_rows($result)>0){
		//输入的用户名和密码是正确的
		//写cookie信息
		$selectusersql="select * from userinfos where username='$username'";
		$result=@mysql_query($selectusersql) or die("登录失败:".mysql_error()."<br/>");
		$result = mysql_fetch_array($result,MYSQL_ASSOC);
		$type = $result["type"];
		setcookie("username",$username,time()+60*60);
		setcookie("type",$type,time()+60*60);
		//跳转页面到主界面
		header("refresh:1;url=index.php");
	}else{
		//输入的用户名和密码不存在
	    echo "<script>alert(\"用户名或密码错误!\");</script>";
	}
}
?>